<script setup lang="ts">
import * as echarts from 'echarts';
import { onMounted } from 'vue';
import { Flow } from '../../api/MyEcharts/index'

var option = {
    tooltip: {
        trigger: 'axis',
        axisPointer: { // 坐标轴指示器，坐标轴触发有效
            type: 'shadow' // 默认为直线，可选为：'line' | 'shadow'
        }
    },
    grid: {
        left: '2%',
        right: '4%',
        bottom: '14%',
        top: '16%',
        containLabel: true
    },
    legend: {
        data: [],
        right: 10,
        top: 12,
        textStyle: {
            color: "#fff"
        },
        itemWidth: 12,
        itemHeight: 10,
    },
    xAxis: {
        type: 'category',
        data: [],
        axisLine: {
            lineStyle: {
                color: 'white'

            }
        },
    },

    yAxis: {
        type: 'value',
        max: '1200',
        axisLine: {
            show: false,
            lineStyle: {
                color: 'white'
            }
        },
        splitLine: {
            show: true,
            lineStyle: {
                color: 'rgba(255,255,255,0.3)'
            }
        },
        axisLabel: {}
    },
    series: [{
        name: '今日外来访客',
        type: 'bar',
        barWidth: '15%',
        itemStyle: {
            normal: {
                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                    offset: 0,
                    color: '#fccb05'
                }, {
                    offset: 1,
                    color: '#f5804d'
                }]),
            },
        },
        data: []
    },
    {
        name: '安防设备用电',
        type: 'bar',
        barWidth: '15%',
        itemStyle: {
            normal: {
                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                    offset: 0,
                    color: '#8bd46e'
                }, {
                    offset: 1,
                    color: '#09bcb7'
                }]),
            }

        },
        data: []
    }]
};

onMounted(async () => {
    var myChart = echarts.init(document.getElementById('main2'));

    let res = await Flow()
    console.log(res);

    let xAxiss: any = option.xAxis.data
    let seriesData: any = option.series[0].data
    let seriesArr: any = option.series[1].data


    option.legend.data = res.data.data.result[0].dimensions.data?.result[0].dimensions;

    for (let i = 0; i < res.data.data.result[0].source.length; i++) {
        xAxiss.push(res.data.data.result[0].source[i].product)
        seriesData.push(res.data.data.result[0].source[i].今日外来访客)
        seriesArr.push(res.data.data.result[0].source[i].昨日外来访客)

    }


    myChart.setOption(option);
})
</script>


<template>
    <div class="right-Bottom">
        <div class="right-Bottom-img">
            <span style="padding-left: 23px; color: aliceblue; font-size: 1.5rem; line-height: 3rem;">校园人员流动情况</span>
        </div>
        <div class="right-Bottom-bottom">
            <div class="right-Bottom-bottom-Top">
                <div>
                    <div class="right-Bottom-bottom-Top-left">

                    </div>
                    <div class="right-Bottom-bottom-Top-right">
                        <div>1</div>
                        <span>昨日到访人员</span>
                    </div>
                </div>
                <div>
                    <div class="right-Bottom-bottom-Top-left-right">

                    </div>
                    <div class="right-Bottom-bottom-Top-right">
                        <div>1</div>
                        <span>今日外来访客</span>
                    </div>
                </div>
            </div>
            <div class="right-Bottom-bottom-foot">
                <div id="main2" style="width: 100%;height:100%;"></div>
            </div>
        </div>
    </div>
</template>

<style scoped lang="scss">
.right-Bottom {
    width: 28rem;
    height: 30rem;
    margin: 0 6rem;
    background-color: rgb(16, 29, 91);

    &-img {
        width: 100%;
        height: 3rem;
        background: url('../../assets/images/RightRight.png') no-repeat center center;
        background-size: 100% 100%;
    }

    &-bottom {
        width: 100%;
        height: 25rem;
        margin-top: 2rem;
        background-color: rgb(29, 46, 107);

        &-Top {
            width: 100%;
            height: 5rem;
            display: flex;

            >div {
                flex: 1;
                color: wheat;
            }

            &-left {
                width: 2rem;
                height: 100%;
                float: left;
                background: url('../../assets/images/right_yestErday.png') no-repeat center center;

                &-right {
                    width: 2rem;
                    height: 100%;
                    float: left;
                    background: url('../../assets/images/right_toDay.png') no-repeat center center;
                }
            }

            &-right {
                width: 10rem;
                height: 100%;
                float: left;
                text-align: center;
                line-height: 30px;
            }
        }

        &-foot {
            width: 100%;
            height: 18rem;
        }
    }
}
</style>